<template>
  <div class="change-class body-bg">
    <div v-if="!initLoading">
      <ul class="change-content" v-if="list.length">
        <li class="buke-items" v-for="(item,index) in list" :key="index">
          <p class="date-time">{{item.leave_time}}</p>
          <div class="buke-items-cont">
            <img class="head-img" :src="child_photo || '/static/images/user.png'" alt="headImg">
            <div class="right">
              <p class="buke-title">{{child_name}}提交的请假</p>
              <p class="buke-text">开始时间：{{item.lesson_list[0].start_class_time}}</p>
              <p class="buke-text">结束时间：{{item.lesson_list[0].end_class_time}}</p>
            </div>
          </div>
        </li>
        <li v-if="isReachBottom" class="pull-loading"><van-loading type="spinner" size="20px" color="#1989fa" /></li>
        <li v-if="isBottom" class="bottom-line">-- 亲，已经到最后了--</li>
      </ul>
      <div v-else class="empty">
        <img src="/static/images/empty-icon.png" alt="空">
        <p class="empty-tips">暂无数据</p>
      </div>
    </div>
    <div v-else class="init-loading"><van-loading type="spinner" color="#1989fa" /></div>
  </div>
</template>

<script>
import Ls from '@/utils/storage'
export default {
  data() {
    return {
      initLoading: true, // 初始加载
      isBottom: false, // 是否加载完全部数据
      isReachBottom: false, // 是否显示加载状态
      child_photo: Ls.getItem("childInfor").child_photo,
      child_name: Ls.getItem("childInfor").child_name,
      curr_page: 1,
      page_size: 10,
      total: "",
      list: []
    }
  },
  onLoad() {
    this.isReachBottom = false;
    this.getClassLeaveApplie();
  },
  onShow() {
    
  },
  // 下拉刷新
  onPullDownRefresh: function() {
    this.curr_page = 1;
    this.isReachBottom = false;
    this.isBottom = false;
    this.getClassLeaveApplie();
  },
  // 上拉加载
  onReachBottom () {
    if(this.isBottom) return;
    this.isReachBottom = true;
    this.getClassLeaveApplie();
  },
  methods: {
    // 获取活动列表
    getClassLeaveApplie() {
      wx.showNavigationBarLoading() //在标题栏中显示加载
      if(this.isReachBottom) {
        this.curr_page++;
      }
      this.$fetch.getClassLeaveApplie({
        curr_page: this.curr_page,
        page_size: this.page_size
      }).then(res=>{
        wx.hideNavigationBarLoading() //在标题栏中隐藏加载
        wx.stopPullDownRefresh(); //完成停止加载
        this.initLoading = false;
        this.total = res.result.total;
        let len = 0;
        if(this.isReachBottom) {
          this.list = [...this.list, ...res.result.data];
          len = this.list.length;
          if(len >= this.total){
            this.isBottom = true;
          }
          this.isReachBottom = false;
          return
        }
        this.list = res.result.data;
        len = this.list.length;
        if(len >= this.total){
          this.isBottom = true;
        }
      }).catch(err=>{
        this.initLoading = false;
        this.isReachBottom = false;
        wx.hideNavigationBarLoading() //在标题栏中隐藏加载
        wx.stopPullDownRefresh(); //完成停止加载
      })
    },
  },
}
</script>

<style lang="less" scope>
.change-class{
  width: 100%;
  min-height: 100vh;
  .change-content{
    width: 100%;
    .buke-items{
      width: 100%;
      overflow: hidden;
      .date-time{
        width: 92px;
        height: 18px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 12px;
        color: #fff;
        background:rgba(0,183,238,1);
        border-radius:0px 10px 10px 0px;
        margin: 10px 0 8px 0;
      }
      .buke-items-cont{
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 100%;
        padding: 10px 16px 14px 16px;
        box-sizing: border-box;
        background: #fff;
        position: relative;
        overflow: hidden;
        .head-img{
          min-width: 75px;
          width: 75px;
          height: 75px;
          border-radius: 50%;
          display: block;
          margin-right: 10px;
        }
        .right{
          height: 70px;
          flex-grow: 1;
          display: flex;
          flex-direction: column;
          justify-content: space-between;
        }
        .buke-title{
          width: 100%;
          font-size: 16px;
          color: #333;
          font-weight: bold;
          // margin-bottom: 14px;
        }
        .buke-text{
          width: 100%;
          font-size: 14px;
          color: #666;
          // margin-bottom: 8px;
        }
        .buke-type{
          width: 100%;
          font-size: 12px;
          color: #00B7EE;
        }
        .buke-btn{
          width:  66px;
          height: 24px;
          background:rgba(0,183,238,1);
          border-radius:  10px;
          display: flex;
          justify-content: center;
          align-items: center;
          font-size: 14px;
          color: #fff;
          font-weight: bold;
          position: absolute;
          right: 16px;
          bottom: 15px;
          &.alreadyEvaluated{
            background: #D6D6D6;
          }
        }
      }
    }
  }
}
</style>
